package com.qianfeng.smartplatform.controller;/*
 *@Description:
 *@author:赵健sb
 *@Date:zjzzz 2022/9/7 17:51
 */

import com.qianfeng.smartplatform.dto.R;
import com.qianfeng.smartplatform.pojo.SysCategory;
import com.qianfeng.smartplatform.service.CategoryService;
    import com.qianfeng.smartplatform.valigroup.Insert;
    import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/categories")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping("/category")
    public R addCategory(@RequestBody @Validated(Insert.class) SysCategory category) {
        categoryService.addCategory(category);

        return R.OK();
    }

    @GetMapping("")
    public R findAllCategory() {
        return R.OK(categoryService.findAllCategories());
    }

    @GetMapping("/category/{cId}")
    public R findCategoryById(@PathVariable Long cId) {
        return R.OK(categoryService.findById(cId));
    }
}
